package com.example.gradu.graduationproject.service.impl;

import com.example.gradu.graduationproject.domain.AttentionUser;
import com.example.gradu.graduationproject.mapper.AttentionUserMapper;
import com.example.gradu.graduationproject.service.AttentionUserService;
import com.example.gradu.graduationproject.util.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (AttentionUser)表服务实现类
 *
 * @author makejava
 * @since 2025-02-20 23:02:34
 */
@Service("attentionUserService")
public class AttentionUserServiceImpl implements AttentionUserService {
    @Resource
    private AttentionUserMapper attentionUserMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param attenid 主键
     * @return 实例对象
     */
    @Override
    public R queryById(Integer attenid) {
        return R.ok().setData(this.attentionUserMapper.queryById(attenid));
    }

    /**
     * 全查询
     *
     * @param attentionUser 筛选条件
     * @return 查询结果
     */
    @Override
    public R queryAll(AttentionUser attentionUser) {
        return R.ok().setData(this.attentionUserMapper.queryAll(attentionUser));
    }

    /**
     * 新增数据
     *
     * @param attentionUser 实例对象
     * @return 实例对象
     */
    @Override
    public R insert(AttentionUser attentionUser) {
        this.attentionUserMapper.insert(attentionUser);
        return R.ok().setData(attentionUser);
    }

    /**
     * 修改数据
     *
     * @param attentionUser 实例对象
     * @return 实例对象
     */
    @Override
    public R update(AttentionUser attentionUser) {
        this.attentionUserMapper.update(attentionUser);
        return R.ok().setData(this.queryById(attentionUser.getAttenid()));
    }

    /**
     * 通过主键删除数据
     *
     * @param attenid 主键
     * @return 是否成功
     */
    @Override
    public R deleteById(Integer attenid) {
        boolean del = this.attentionUserMapper.deleteById(attenid) > 0;
        return R.ok().setData(del);
    }

    /**
     * 查询博主是否被当前用户关注
     *
     * @param attentionUser 当前用户id，查询用户id
     * @return 是否关注
     */
    @Override
    public R queryIfAtten(AttentionUser attentionUser){
        boolean ifAtten = this.attentionUserMapper.queryAll(attentionUser).size() > 0;
//        ifAtten = true 已关注
//        ifAtten = false 没关注
        return R.ok().setData(ifAtten);
    }
}

